package cn.dy.sbo.model;

import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;
import org.hibernate.annotations.OnDelete;
import org.hibernate.annotations.OnDeleteAction;

import cn.common.lib.springside.entity.AutoIdEntity;

@Entity
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class Flow extends AutoIdEntity
{
    /**
	 * 
	 */
    private static final long serialVersionUID = 1L;

    private String            code;                 // 编号

    private String            name;                 // 名称

    private String            enname;               // en名称

    private int               orderNum;             // 序列号码

    private Flow              parent;

    private List<Flow>        childs;

    private List<StepField>   fields;

    private FlowType          type;

    private String            typeCode;

    private String            flowTemplate;         // 流程附加数据模板（json）

    @Column(length = 20)
    public String getCode()
    {
        return code;
    }

    public void setCode(String code)
    {
        this.code = code;
    }

    @Column(length = 200)
    public String getName()
    {
        return name;
    }

    public void setName(String name)
    {
        this.name = name;
    }

    @Column(length = 200)
    public String getEnname()
    {
        return enname;
    }

    public void setEnname(String enname)
    {
        this.enname = enname;
    }

    @ManyToOne(cascade = CascadeType.REFRESH, fetch = FetchType.LAZY)
    @NotFound(action = NotFoundAction.IGNORE)
    public FlowType getType()
    {
        return type;
    }

    public void setType(FlowType type)
    {
        this.type = type;
    }

    @ManyToOne(cascade = CascadeType.REFRESH, fetch = FetchType.LAZY)
    @NotFound(action = NotFoundAction.IGNORE)
    @JoinColumn(name = "parent_id")
    public Flow getParent()
    {
        return parent;
    }

    public void setParent(Flow parent)
    {
        this.parent = parent; 
    }

    @OneToMany(targetEntity = Flow.class)
    @JoinColumn(name = "parent_id")
    @OrderBy(value = "orderNum")
    @Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
    public List<Flow> getChilds()
    {
        return childs;
    }

    public void setChilds(List<Flow> childs)
    {
        this.childs = childs;
    }

    @OneToMany(targetEntity = StepField.class)
    @JoinColumn(name = "step")
    @OrderBy(value = "orderNum")
    @Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
    public List<StepField> getFields()
    {
        return fields;
    }

    public void setFields(List<StepField> fields)
    {
        this.fields = fields;
    }

    @Column(length = 20)
    public String getTypeCode()
    {
        return typeCode;
    }

    public void setTypeCode(String typeCode)
    {
        this.typeCode = typeCode;
    }

    public int getOrderNum()
    {
        return orderNum;
    }

    public void setOrderNum(int orderNum)
    {
        this.orderNum = orderNum;
    }

    @Column(length = 1000)
    public String getFlowTemplate()
    {
        return flowTemplate;
    }

    public void setFlowTemplate(String flowTemplate)
    {
        this.flowTemplate = flowTemplate;
    }

}
